package com.imoblife.brainwavestus.util;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import com.imoblife.brainwavestus.BrainWavestusApplication;

public class ScreenUtil {
	Activity mActivity;

	public ScreenUtil(Activity activity) {
		mActivity = activity;
		setRequestedOrientation();
	}

	public void setContentView(int layoutResID) {
		mActivity.setContentView(layoutResID);
	}

	/**
	 * 设置屏幕朝向
	 */
	public void setRequestedOrientation() {
		
		BrainWavestusApplication applicaion = 
				(BrainWavestusApplication)mActivity.getApplication();
		// 如果是平板则设置为横屏
		if (applicaion.isPad()) {

			if (mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
				mActivity
						.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			}

			// 否则为竖屏
		} else {

			if (mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
				mActivity
						.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			}

		}

	}
	
	public int dpTopx(int dp) {
		DisplayMetrics displayMetrics = mActivity.getResources()
				.getDisplayMetrics();
		return (int) (dp * displayMetrics.density + 0.5);
	}
	
}
